package com.wanmait.recruitment.service.impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.DegreeMapper;
import com.wanmait.recruitment.pojo.Degree;
import com.wanmait.recruitment.service.DegreeService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class DegreeServiceImpl implements DegreeService {
    @Resource
    private DegreeMapper degreeMapper;
    @Override
    //@CacheEvict(value = "degreeCache",allEntries = true)
    public void insert(Degree object) {
        degreeMapper.insertSelective(object);
    }

    @Override
    //@CacheEvict(value = "degreeCache",allEntries = true)
    public void delete(Integer id) {
        degreeMapper.del(id);
    }

    @Override
    public void delete(String ids) {

    }

    @Override
    //@CacheEvict(value = "degreeCache",allEntries = true)
    public void update(Degree object) {
        degreeMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public Degree findById(Integer id) {
        return null;
    }

    @Override
    //@Cacheable("degreeCache")
    public List<Degree> findAll() {
        return degreeMapper.selectList();
    }

    @Override
    public List<Degree> findAll(Degree object) {
        return null;
    }

    @Override
    public PageInfo<Degree> findPage(int pageNum, int pageSize) {
        return null;
    }

    @Override
    public Degree findByName(String name) {
        return degreeMapper.findByName(name);
    }

    @Override
    //@CacheEvict(value = "degreeCache",allEntries = true)
    public void batchDel(String ids) {
        String[] idArr = ids.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<idArr.length;i++) {
            list.add(Integer.parseInt(idArr[i]));
        }
        degreeMapper.batchDel(list);
    }
}
